import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type ONYXKEYS from '@src/ONYXKEYS';
import type CollectionDataSet from '@src/types/utils/CollectionDataSet';
import type * as OnyxCommon from './OnyxCommon';

/**
 * Model for scheduled called on the report
 */
type CalendlyCall = {
    /** Status of the call */
    status: ValueOf<typeof CONST.SCHEDULE_CALL_STATUS>;

    /** The setup specialist the user confirmed the call with */
    host: number;

    /** The selected date and time in YYYY-MM-DD HH:MM:SS format for the call */
    eventTime: string;

    /** Unique identifier of the event  */
    eventURI: string;

    /** The time the call was inserted in this NVP in YYYY-MM-DD HH:MM:SS format */
    inserted: string;
};

/**
 * Guide call schedule
 */
type GuideCalendlySchedule = {
    /**
     * Guide Email
     */
    guideEmail: string;
    /**
     * Available slots for the guide
     */
    timeSlots: Array<{
        /**
         * Calendly event scheduling url
         */
        schedulingURL: string;

        /**
         * Start time for the slow
         */
        startTime: string;
    }>;
};

/**
 * Guide Account ID
 */
type GuideAccountID = string;

/** Model of additional report details */
type ReportNameValuePairs = OnyxCommon.OnyxValueWithOfflineFeedback<{
    /** Whether the report is an archived room */
    private_isArchived?: string;

    /** Scheduled calls for the user on #admin rooms */
    calendlyCalls?: CalendlyCall[];

    /** Guides Call schedule */
    calendlySchedule?: {
        /** Whether the API call is loading */
        isLoading?: boolean;

        /** Whether the account was merged successfully */
        data?: Record<GuideAccountID, GuideCalendlySchedule>;

        /** Errors while merging the account */
        errors?: OnyxCommon.Errors;
    };

    /** The time the report export failed */
    exportFailedTime?: string;

    /** Agent Zero processing request indicator message */
    agentZeroProcessingRequestIndicator?: string;

    /** Title field configuration copied from policy - presence indicates auto-generated names are allowed */
    // eslint-disable-next-line @typescript-eslint/naming-convention
    expensify_text_title?: {
        /** Name of the field */
        name: string;

        /** Default value assigned to the field */
        defaultValue: string;

        /** Unique id of the field */
        fieldID: string;

        /** Position at which the field should show up relative to the other fields */
        orderWeight: number;

        /** Type of report field */
        type: string;

        /** Tells if the field is required or not */
        deletable: boolean;

        /** Value of the field */
        value?: string | null;

        /** Value of the target */
        target?: 'expense' | 'invoice' | 'paycheck';

        /** Options to select from if field is of type dropdown */
        values: string[];

        /** Tax UDFs have keys holding the names of taxes (eg, VAT), values holding percentages (eg, 15%) and a value indicating the currently selected tax value (eg, 15%). */
        keys: string[];

        /** list of externalIDs, this are either imported from the integrations or auto generated by us, each externalID */
        externalIDs: string[];

        /** Collection of flags that state whether drop down field options are disabled */
        disabledOptions: boolean[];

        /** Is this a tax user defined report field */
        isTax: boolean;

        /** This is the selected externalID in an expense. */
        externalID?: string | null;

        /** Automated action or integration that added this report field */
        origin?: string | null;

        /** This is indicates which default value we should use. It was preferred using this over having defaultValue (which we have anyway for historical reasons), since the values are not unique we can't determine which key the defaultValue is referring too. It was also preferred over having defaultKey since the keys are user editable and can be changed. The externalIDs work effectively as an ID, which never changes even after changing the key, value or position of the option. */
        defaultExternalID?: string | null;
    };
}>;

/** Collection of reportNameValuePairs, indexed by reportNameValuePairs_{reportID} */
type ReportNameValuePairsCollectionDataSet = CollectionDataSet<typeof ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS>;

export default ReportNameValuePairs;

export type {ReportNameValuePairsCollectionDataSet, CalendlyCall};
